<?php
/**
* Georgia Institute of Technology Base PHP File
*
* This file contains global php variables, classes, and methods
* for use within the Georgia Institute of Technology website (http://www.gatech.edu).
*
* @author Office of Communications and Marketing <web@comm.gatech.edu>
* @version 0.1
* @package gtbase
*/

/**
* status variables
*/
$STATUS_PENDING = 0;
$STATUS_ACTIVE = 1;
$STATUS_INACTIVE = 2;

/**
* borrow and no-borrow variables added to help filter dynabot 
* items meant only to display on outside sites (i.e., chemistry) -- e.huffman 8/16/05
*/
$STATUS_NO_BORROW = 0;
$STATUS_BORROW = 1;

/**
* form display handlers
*/
$FORM = 1;
$NEXT = 2;
$SUCCESS = 3;
$ERROR = 4;
$POLL = 5;
$RESULTS = 6;

/**
* list of words to ignore in News Room search
*/
$SEARCH_IGNORE_LIST = array("the","and","of","by","in","a","i","is","are","not","on");

/**
* database aliases
*/
$DYNABOT_DB = "dynabot2";
$GATECH_DB = "gatech";
$SURVEYS_DB = "surveys";
$PROFILES_DB = "profiles";

/**
* php: getimagesize - flag values corresponding to the
* IMAGETYPE constants that were added in PHP 4.3.0
*/
$image_types = array(1=>'GIF',2=>'JPG',3=>'PNG',4=>'SWF',5=>'PSD',6=>'BMP',7=>'TIFF',8=>'TIFF',9=>'JPC',10=>'JP2',11=>'JPX',12=>'JB2',13=>'SWC',14=>'IFF',15=>'WBMP',16=>'XBM'); 

/**
* Convert text to html formatted string
* @param string $string the string to process
* @return string $encoded the encoded string
*/
function to_html($string) {
	$encoded = stripslashes($string);
	$encoded = str_replace (chr(10), '<br />', $encoded); // carriage return to new paragraph
	$encoded = str_replace (chr(145), '&#8216;', $encoded); // left single quote
	$encoded = str_replace (chr(146), '&#8217;', $encoded); // right single quote
	$encoded = str_replace (chr(147), '&#8220;', $encoded); // left double quote
	$encoded = str_replace (chr(148), '&#8221;', $encoded);// right double quote
	$encoded = str_replace (chr(233), '&#233;', $encoded); // accented e
	$encoded = str_replace (' p.m.', '<span class="fauxsmallcap">PM</span>', $encoded); // start prettifying AM and PM
	$encoded = str_replace (' a.m.', '<span class="fauxsmallcap">AM</span>', $encoded);
	$encoded = str_replace ('p.m.', '<span class="fauxsmallcap">PM</span>', $encoded);
	$encoded = str_replace ('a.m.', '<span class="fauxsmallcap">AM</span>', $encoded);
	#$encoded = preg_replace ('/(\d)([ ]?)(am)/', '$1<span class="fauxsmallcap">AM</span>', $encoded);
	#$encoded = preg_replace ('/(\d)([ ]?)(pm)/', '$1<span class="fauxsmallcap">PM</span>', $encoded); // stop prettifying AM and PM
	$encoded = str_replace (chr(150), '&#8211;', $encoded); // en dash
	$encoded = str_replace (chr(151), '&#8212;', $encoded); // em dash
	$encoded = preg_replace ('/([ ]?)(--)([ ]?)/', '&#8212;', $encoded); // double dashes to em dash, removing extra spaces
	$encoded = str_replace ('\'s ', '&#8217;s ', $encoded); // proper apostrophe for possessives
	$encoded = str_replace ('\'re ', '&#8217;re ', $encoded); // proper apostrophe for contractions with 'are' or 'were'
	$encoded = str_replace ('n\'t', 'n&#8217;t', $encoded); // proper apostrophe for contractions with 'not'
	$encoded = str_replace ('I\'m', 'I&#8217;m', $encoded); // proper apostrophe for 'I am' contraction
	$encoded = str_replace ('& ', '&amp; ', $encoded); // ampersands
	$encoded = str_replace ('\' ', '&#8217; ', $encoded); // apostrophes and right single quotes for '+space
	$encoded = str_replace (' \'', ' &#8216;', $encoded); // left single quotes for space+'
	$encoded = str_replace (' "', ' &#8220;', $encoded); // left double quotes for space+"
	$encoded = str_replace ('<p>"', '<p>&#8220;', $encoded); // left double quotes for " at beginning of paragraph
	$encoded = str_replace ('"</p>', '&#8221;</p>', $encoded); // right double quotes for " at end of paragraph
	$encoded = str_replace ('" ', '&#8221; ', $encoded); // right double quotes for "+space
	$encoded = str_replace ('."', '.&#8221;', $encoded); // right double quotes for " after period
	$encoded = str_replace ('>>', '&gt;&gt;', $encoded); // sometimes used in links
	$encoded = str_replace ('<<', '&lt;&lt;', $encoded); // sometimes used in links
	$encoded = preg_replace ('/(\w) (\d)/', '$1&nbsp;$2', $encoded); // prevent line breaks before numbers
	return $encoded;
}

/**
* Verify display_stop_date is in the future
* @param string $priority_id the string to process
* @return string $priority_id if true, null if false
*/
function current_check($priority_id) {
    global $STATUS_ACTIVE;
    global $STATUS_BORROW;

    // determine which db table to check
    if (substr($priority_id,0,1) == 'n') $table = "news"; else $table = "events";

    // check to make sure priority array id is current
    // borrow parameter added to help filter dynabot items meant only to display on outside sites (i.e., chemistry) -- e.huffman 10/25/05
    $query = "SELECT id 
			 FROM   ".$table." 
			 WHERE  status =".$STATUS_ACTIVE."
					AND
					borrow =".$STATUS_BORROW."
					AND
					display_start_date <= '".date('Y-m-d')."'
					AND
					display_stop_date >= '".date('Y-m-d')."'
					AND
					id =".substr($priority_id,1);
	$result = mysql_query($query);
	$priority_check = mysql_fetch_assoc($result);
	//$priority_check = db_select($DYNABOT_DB, $priority_check_query); 

	// if story is not current, replace array value with empty value, else, return original id
	if (!$priority_check) return(''); else return($priority_id);
}


/**
* Verify feature value for news item
* @param string $priority_id the string to process
* @return string $priority_id if 0, null if 1
*/
function feature_check($priority_id) {
	$feature_check_query = "SELECT feature FROM news WHERE id =".$priority_id;
	$result = mysql_query($feature_check_query);
	$feature_check = mysql_fetch_assoc($result);
	//$feature_check = db_select($DYNABOT_DB, $feature_check_query);

	// if story is not feature, replace array value with empty value, else, return original id
	if ( $feature_check['feature'] == 1 ) return(''); else return($priority_id);
}
?>